﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

public partial class stulogin : System.Web.UI.Page
{
    string n = string.Empty;
    string p = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.Form["n"])) {
            n = Request.Form["n"];
        }
        if (!string.IsNullOrEmpty(Request.Form["p"])) {
            p = Request.Form["p"];
        }
        if (n == "") {
            Response.Write("e3"); Response.End();
        }
        if (p == "") {
            Response.Write("e1"); Response.End();
        }

        string result = "";

        Exam.Core.Model.Student model = new Exam.Core.DAL.Student().StudentByNumber(Server.HtmlEncode(n));
        if (model.StudentPassword == "") {//用户不存在
            result = "e0";
        }
        else {
            if (model.StudentPassword.ToLower().Trim() == p.ToLower().Trim()) {//密码正确
                StringBuilder sb = new StringBuilder();
                sb.Append(model.StudentID.Trim());
                sb.Append("|");
                sb.Append(model.StudentNumber.Trim());
                sb.Append("|");
                sb.Append(Server.UrlEncode(model.StudentName.Trim()));
                sb.Append("|");
                sb.Append(model.StudentPassword.Trim());
                sb.Append("|");
                sb.Append(model.StudentEmail.Trim());
                sb.Append("|");
                sb.Append(model.DepartmentID.Trim());
                Cookie.SaveCookie(ExamSys.cookies_name.Trim(), sb.ToString(), 720);
                result = "ok";
            }
            else {//密码错误
                result = "e1";
            }
        }

        Response.Write(result);
        Response.End();

    }
}